package com.woniuxy.producer;

import com.woniuxy.util.RabbitmqConst;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @BelongsProject: pigTrotterStore
 * @BelongsPackage: com.woniuxy.producer
 * @Author: Quan
 * @Date: 2025/3/21 10:24
 */
@Component
public class DelayProducer {
	@Autowired
	private RabbitTemplate rabbitTemplate;

	public void send(String routeKey, String msg, Integer ttl) {
		rabbitTemplate.convertAndSend(RabbitmqConst.DELAY_EXCHANGE, routeKey, msg, new MessagePostProcessor() {
			@Override
			public Message postProcessMessage(Message message) throws AmqpException {
				message.getMessageProperties().setDelay(ttl);
				return message;
			}
		});
	}

}
